package com.rao.controller;

import com.rao.config.websecurity.permitcollect.PermitAnyOne;
import com.rao.core.startcollect.StartPrintUrlTag;

import com.rao.entity.User;
import com.rao.entity.VO.CommonResponseVO;
import com.rao.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "LoginController", description = "登录")
@RequestMapping("/LoginController")
public class LoginController {

    @Autowired
    LoginService loginService;

    /*
     * {
     *   "password": "rao3030",
     *   "username": "rao3030"
     * }
     */
    @PermitAnyOne
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @StartPrintUrlTag
    @ApiOperation("登录按钮")
    public CommonResponseVO login(@RequestBody User user) {
        String loginToken = loginService.login(user.getUsername(), user.getPassword());
        return CommonResponseVO.success(CommonResponseVO.SUCCESS_STATUS, "登录-succeed", loginToken);
    }
}
